$( document ).ready(function() {
	 // Handler for .ready() called.
	if ($("#drug-brand-registration-form").length > 0) {
		$("#drug-brand-registration-form").validate({
			rules: {
				"guiDrugBrand.name": {
					required: true
				}
			},								  
											  
			messages: {
				"guiDrugBrand.name": {
					required: "Please specify the drug brand name"
				}
			},
			
			submitHandler: function(form) { 
				form.submit();  
			}
		});
	}

	if ($("#btn-delete").length > 0) {
		$("#btn-delete").on('click', function(e){
			e.preventDefault();
			$.Dialog({
				shadow: true,
				overlay: true,
				icon: '<span class="icon-remove"></span>',
				title: 'Delete Confirmation',
				width: 400,
				padding: 10,
				onShow: function(_dialog){
 					var content = _dialog.children('.content');
 					content.html('<div class="subheader-secondary" style="width:400px">Do you want to delete this drug brand?</div><br/><div><a id="btn-delete" href="' + $("#btn-delete").attr('href') + '" class="button">Delete</a></div>');
				}
			});
		});
	}
	
	//error message notifier
	if ($("ul.errorMessage li span").length > 0) {
		$("ul.errorMessage li span").each(function(){
			$.Notify({
					 	  caption: "Try Again!",
						  content: $(this).text(),
						  timeout: 5000,
						  style: {background: '#1ba1e2', color: 'white'}
					 });
		});
	}
		
});
